package cn.my.shellSort;

import java.util.Arrays;

public class ShellSort {
	public static void shellSort(int[] a){
		int d = a.length / 2;
		while (d >= 1){
			for (int i=0; i<d; i++){
				for (int j=i+d; j<a.length; j+=d){
					int temp = a[j];
					int pos = j - d;
					while (pos>=0 && a[pos]>temp){
						a[pos+d] = a[pos];
						pos -= d;
					}
					a[pos+d] = temp;
				}
			}
			d = d / 2;
		}
	}
	public static void main(String[] args) {
		int a[] = {9, 1, 2, 5, 7, 4, 8, 6, 3, 5};
		shellSort(a);
		System.out.println(Arrays.toString(a));
	}
}
